package com.ye.personnel.common.page;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 分页查询参数, 使用Map参数
 *
 * @author ye
 * @since 2021-09-01 15:42:37
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class PageQuery<T> extends LinkedHashMap<String, Object> {


  /**
   * mybatis-plus分页参数
   */
  private Page<T> page;

  /**
   * 当前页码
   */
  private int curPage = 1;

  /**
   * 每页条数
   */
  private int pageSize = 10;

  public PageQuery(Map<String, Object> params) {
    this.putAll(params);
    String page = "page";
    String size = "pageSize";
    //分页参数z
    if (params.get(page) != null) {
      curPage = Integer.parseInt((String) params.get(page));
    }
    if (params.get(size) != null) {
      pageSize = Integer.parseInt((String) params.get(size));
    }
    // mybatis-plus分页
    this.page = new Page<>(curPage, pageSize);
  }
}
